package com.example.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.example.domain.OfficeType;
import com.example.service.IOfficeTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 办公用品类型Controller
 * 
 * @author whj
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/officeType")
public class OfficeTypeController extends BaseController
{
    @Autowired
    private IOfficeTypeService officeTypeService;

    /**
     * 查询办公用品类型列表
     */
    @RequiresPermissions("office:officeType:list")
    @GetMapping("/list")
    public TableDataInfo list(OfficeType officeType)
    {
        startPage();
        List<OfficeType> list = officeTypeService.selectOfficeTypeList(officeType);
        return getDataTable(list);
    }

    /**
     * 导出办公用品类型列表
     */
    @RequiresPermissions("office:officeType:export")
    @Log(title = "办公用品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OfficeType officeType)
    {
        List<OfficeType> list = officeTypeService.selectOfficeTypeList(officeType);
        ExcelUtil<OfficeType> util = new ExcelUtil<OfficeType>(OfficeType.class);
        util.exportExcel(response, list, "办公用品类型数据");
    }

    /**
     * 获取办公用品类型详细信息
     */
    @RequiresPermissions("office:officeType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(officeTypeService.selectOfficeTypeById(id));
    }

    /**
     * 新增办公用品类型
     */
    @RequiresPermissions("office:officeType:add")
    @Log(title = "办公用品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OfficeType officeType)
    {
        return toAjax(officeTypeService.insertOfficeType(officeType));
    }

    /**
     * 修改办公用品类型
     */
    @RequiresPermissions("office:officeType:edit")
    @Log(title = "办公用品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OfficeType officeType)
    {
        return toAjax(officeTypeService.updateOfficeType(officeType));
    }

    /**
     * 删除办公用品类型
     */
    @RequiresPermissions("office:officeType:remove")
    @Log(title = "办公用品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(officeTypeService.deleteOfficeTypeByIds(ids));
    }
}
